﻿Imports AugmentLib.Database
Imports System.Configuration.ConfigurationManager
Imports AugmentLib.InputOutput.Encryption
Partial Class TransHistory
    Inherits System.Web.UI.Page

#Region " Properties "

    Public Property CurrentPage() As Integer
        Get
            'Looks for the current page in ViewState
            Dim objPage As Object = ViewState("_CurrentPage")
            If objPage Is Nothing Then
                Return 0
            Else
                'default to showing the first page
                Return CInt(objPage)
            End If
        End Get
        Set(ByVal value As Integer)
            ViewState("_CurrentPage") = value
        End Set
    End Property

    Public Property PageSize() As Integer
        Get
            'Looks for the current page in ViewState
            Dim objPageSize As Object = ViewState("_PageSize")
            If objPageSize Is Nothing Then
                Return 25
            Else
                'default to showing the first page
                Return CInt(objPageSize)
            End If
        End Get
        Set(ByVal value As Integer)
            ViewState("_PageSize") = value
        End Set
    End Property

#End Region

#Region " Paging and Page Size "

    Protected Sub lnkHead10Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkHead10Item.Click
        PageSize = 10
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkHead25Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkHead25Item.Click
        PageSize = 25
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkHead100Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkHead100Item.Click
        PageSize = 100
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkHead150Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkHead150Item.Click
        PageSize = 150
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkFoot10Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFoot10Item.Click
        PageSize = 10
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkFoot25Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFoot25Item.Click
        PageSize = 25
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkFoot100Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFoot100Item.Click
        PageSize = 100
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkFoot150Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFoot150Item.Click
        PageSize = 150
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub btnMoveFirst_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMoveFirst.Click
        CurrentPage = 0
        txtPageNo.Text = CurrentPage + 1
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub btnPrevious_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
        If CurrentPage > 0 Then
            CurrentPage = CurrentPage - 1
            txtPageNo.Text = CurrentPage + 1
            btnSearch_Click(sender, e)
        End If
    End Sub

    Protected Sub btnGo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGo.Click
        If CInt(txtPageNo.Text < 1) Then
            txtPageNo.Text = 1
        End If

        If CInt(txtPageNo.Text > CInt(lblMaxPageCount.Text)) Then
            txtPageNo.Text = CInt(lblMaxPageCount.Text) + 1
        End If

        CurrentPage = CInt(txtPageNo.Text) - 1
        btnSearch_Click(sender, e)

    End Sub

    Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click
        If CurrentPage < CInt(lblMaxPageCount.Text) Then
            CurrentPage = CurrentPage + 1
            txtPageNo.Text = CurrentPage + 1
            btnSearch_Click(sender, e)
        End If
    End Sub

    Protected Sub btnMoveLast_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMoveLast.Click
        CurrentPage = CInt(lblMaxPageCount.Text)
        txtPageNo.Text = CurrentPage + 1
        btnSearch_Click(sender, e)
    End Sub

#End Region

    Dim sum, grossamount As Decimal

    Private Sub LoadPropertyType(Optional ByVal Type As String = "")

        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()
        If Type = "" Then
            objDB.dbVariable.SQLString = "SELECT TypeId,Type,CASE WHEN (LEN(TypeDesc)>=150) THEN SUBSTRING(TypeDesc, 1, 150) + '...' ELSE TypeDesc END AS TYPEDESC FROM AW_PropertyType ORDER BY Type"
        Else
            objDB.dbVariable.SQLString = "SELECT TypeId,Type,CASE WHEN (LEN(TypeDesc)>=150) THEN SUBSTRING(TypeDesc, 1, 150) + '...' ELSE TypeDesc END AS TYPEDESC FROM AW_PropertyType WHERE Type LIKE @Type ORDER BY Type"
            objDB.AddParameter("Type", Data.SqlDbType.NVarChar, "%" & Type & "%")
        End If
        objDB.FillData(TempDT, "PropertyType", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()

        repPropertyType.DataSource = TempDT
        repPropertyType.DataBind()

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Session("StaffId") Is Nothing Then
            Response.Redirect("Default.aspx")
        ElseIf Session.Item("StaffType").ToString = "2" Then
            'Response.Redirect("Default.aspx")
            lnkGross.Visible = False
        End If

        'Edited by minginn @ 27/6/2011 - to load the same search when user back from other page
        If Not Session("Back") Is Nothing Then
            Dim strBack As String = Session("Back").ToString
            Dim arr() As String = strBack.Split("ڡ")
            '0-Back Page
            '1-Project
            '2-Road Name
            '3-Unit Number
            '4-Property Type
            '5-Location Name
            '6-List Type
            '7-Page Size
            '8-Current Page
            If arr(0).ToString.Contains("transHistory.aspx") Then
                txtProject.Text = arr(1).ToString
                txtRoadName.Text = arr(2).ToString
                txtUnitNumber.Text = arr(3).ToString
                txtPropertyType.Text = arr(4).ToString
                txtLocationName.Text = arr(5).ToString
                ddlListType.SelectedValue = arr(6).ToString
                PageSize = CInt(arr(7).ToString)
                CurrentPage = CInt(arr(8).ToString)
                Session.Remove("Back")
                SearchCompleteList()
            Else
                Session.Remove("Back")
            End If
        End If

        If Not Page.IsPostBack Then

            lblUserID.Text = Session.Item("StaffId").ToString
            lblStaffType.Text = Session.Item("StaffType").ToString

            If Not Session.Item("entry") Is Nothing Then
                lblMsgSuccessful.Text = "<strong>Information:</strong>Staff <strong>" & Session.Item("entry").ToString & "</strong> transaction was updated"
                divSuccessful.Visible = True
                Session.Remove("entry")
            End If

        End If

    End Sub

    Protected Sub btnSearchPropertyType_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearchPropertyType.Click
        If txtPropertyType.Text = "" Then
            LoadPropertyType()
        Else
            LoadPropertyType(txtPropertyType.Text)
        End If
        mpePropertyTypeEntry.Show()
    End Sub

    Protected Sub repPropertyType_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles repPropertyType.ItemCommand

        If e.CommandName = "SelectType" Then
            Dim PropertyType As String = CType(repPropertyType.Items(e.CommandArgument).FindControl("lnkRepPropertyType"), LinkButton).Text
            txtPropertyType.Text = PropertyType
        End If
    End Sub

    Protected Sub btnResetSearchFilter_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnResetSearchFilter.Click
        txtProject.Text = String.Empty
        txtRoadName.Text = String.Empty
        txtLocationName.Text = String.Empty
        txtUnitNumber.Text = String.Empty
        txtPropertyType.Text = String.Empty
    End Sub

    Private Sub SearchCompleteList()

        sum = 0
        grossamount = 0
       
        Dim strWhere As String = ""
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim strTrasactionType As String = ""
        Dim strStatus As String = ""

        If txtProject.Text.Trim <> "" Then
            strWhere = strWhere & " AND AW_Project.Project LIKE @Project "
            objDB.AddParameter("Project", Data.SqlDbType.NVarChar, "%" & txtProject.Text.Trim & "%")
        End If

        If txtRoadName.Text <> "" Then
            strWhere = strWhere & " AND AW_Road.Road LIKE @Road "
            objDB.AddParameter("Road", Data.SqlDbType.NVarChar, "%" & txtRoadName.Text.Trim & "%")
        End If

        If txtLocationName.Text <> "" Then
            strWhere = strWhere & " AND AW_Location.Location LIKE @Location "
            objDB.AddParameter("Location", Data.SqlDbType.NVarChar, "%" & txtLocationName.Text.Trim & "%")
        End If

        If txtUnitNumber.Text <> "" Then
            strWhere = strWhere & " AND AW_Property.UnitNumber LIKE @UnitNo "
            objDB.AddParameter("UnitNo", Data.SqlDbType.NVarChar, "%" & txtUnitNumber.Text.Trim & "%")
        End If

        If txtPropertyType.Text <> "" Then
            strWhere = strWhere & " AND AW_PropertyType.Type LIKE @Type "
            objDB.AddParameter("Type", Data.SqlDbType.NVarChar, "%" & txtPropertyType.Text.Trim & "%")
        End If

        If ddlListType.SelectedValue = "0" Then
            strTrasactionType = "AW_SaleTransaction.Status"
        Else
            strTrasactionType = "AW_RentTransaction.Status"
        End If

        Select Case ddlListStatus.SelectedValue
            Case 0 'NEW
            Case 1 'PENDING SIGNING
            Case 2 'PENDING COLLECTION
            Case 3 'COMPLETED
            Case 4 'RELIST
                strStatus = strTrasactionType & "=4 "
            Case 5 'RENEW
                strStatus = strTrasactionType & "=5 "
            Case 6 'NFSR
            Case 7 'DELETE
                strStatus = strTrasactionType & "=7 "
            Case 8 'ALL
                strStatus = strTrasactionType & "=4 Or " & strTrasactionType & "=5 Or " & strTrasactionType & "=7 "
        End Select


       

        objDB.OpenConnection()

        If ddlListType.SelectedValue = "0" Then
            'Edited By minginn @ 30/9/2011 - Use Initial instead of name
            'Added by : Daniel Lee
            'Date : 24-Aug-2011
            'To include undo date AW_SalesTranaction.UndoDate to check if the transaction is being aborted if yes then show (abort)
            lblCurrentTransType.Text = "S"
            If lblStaffType.Text = "2" Then
                strWhere = strWhere & " AND (AW_SaleTransaction.TransactorId=@UserId OR AW_SaleTransaction.ListerId=@UserId) "
                objDB.AddParameter("UserId", Data.SqlDbType.UniqueIdentifier, New Guid(lblUserID.Text.Trim))
            End If
            objDB.dbVariable.SQLString = "SELECT AW_Property.PropertyId ,AW_Property.UnitNumber,AW_Road.Road, AW_Location.Location,AW_State.State, AW_Country.Country, " & _
                             "AW_Project.Project, AW_Project.ProjectDesc,AW_Project.Picture,AW_PropertyType.Type, AW_PropertyType.TypeDesc, " & _
                             "AW_SaleTransaction.TransactionId AS TransactionId,AW_SaleTransaction.TransactDate,AW_SaleTransaction.Status,AW_SaleTransaction.GrossAmount, " & _
                             "AW_SaleTransaction.TransactorId, AW_Staff.Name, AW_Staff.Initial, AW_SaleTransaction.UndoDate  " & _
                             "FROM AW_Property " & _
                             "INNER JOIN AW_SaleTransaction ON AW_Property.PropertyId = AW_SaleTransaction.PropertyId " & _
                             "LEFT OUTER JOIN AW_Road ON AW_Property.RoadId=AW_Road.RoadId " & _
                             "LEFT OUTER JOIN AW_Location ON AW_Road.LocationId=AW_Location.LocationId " & _
                             "LEFT OUTER JOIN AW_State ON AW_Location.StateId=AW_State.StateId " & _
                             "LEFT OUTER JOIN AW_Country ON AW_State.CountryId=AW_Country.CountryId " & _
                             "LEFT OUTER JOIN AW_Project ON AW_Property.ProjectId=AW_Project.ProjectId " & _
                             "LEFT OUTER JOIN AW_PropertyType ON AW_Property.PropertyTypeId=AW_PropertyType.TypeId " & _
                             "LEFT OUTER JOIN AW_Staff ON AW_SaleTransaction.TransactorId=AW_Staff.StaffId " & _
                             "WHERE " & strStatus & _
                             strWhere & lblhidSortType.Text
        Else
            'Added by : Daniel Lee
            'Date : 24-Aug-2011
            'To include undo date AW_RentTransaction.UndoDate to check if the transaction is being aborted if yes then show (abort)
            lblCurrentTransType.Text = "R"
            If lblStaffType.Text = "2" Then
                strWhere = strWhere & " AND (AW_RentTransaction.TransactorId=@UserId OR AW_RentTransaction.ListerId=@UserId) "
                objDB.AddParameter("UserId", Data.SqlDbType.UniqueIdentifier, New Guid(lblUserID.Text.Trim))
            End If
            objDB.dbVariable.SQLString = "SELECT AW_Property.PropertyId ,AW_Property.UnitNumber,AW_Road.Road, AW_Location.Location,AW_State.State, AW_Country.Country, " & _
                             "AW_Project.Project, AW_Project.ProjectDesc,AW_Project.Picture,AW_PropertyType.Type, AW_PropertyType.TypeDesc, " & _
                             "AW_RentTransaction.TransactionId as TransactionId,AW_RentTransaction.TransactDate,AW_RentTransaction.Status,AW_RentTransaction.GrossAmount, " & _
                             "AW_RentTransaction.TransactorId, AW_Staff.Name, AW_Staff.Initial, AW_RentTransaction.UndoDate " & _
                             "FROM AW_Property " & _
                             "INNER JOIN AW_RentTransaction ON AW_Property.PropertyId = AW_RentTransaction.PropertyId " & _
                             "LEFT OUTER JOIN AW_Road ON AW_Property.RoadId=AW_Road.RoadId " & _
                             "LEFT OUTER JOIN AW_Location ON AW_Road.LocationId=AW_Location.LocationId " & _
                             "LEFT OUTER JOIN AW_State ON AW_Location.StateId=AW_State.StateId " & _
                             "LEFT OUTER JOIN AW_Country ON AW_State.CountryId=AW_Country.CountryId " & _
                             "LEFT OUTER JOIN AW_Project ON AW_Property.ProjectId=AW_Project.ProjectId " & _
                             "LEFT OUTER JOIN AW_PropertyType ON AW_Property.PropertyTypeId=AW_PropertyType.TypeId " & _
                             "LEFT OUTER JOIN AW_Staff ON AW_RentTransaction.TransactorId=AW_Staff.StaffId " & _
                             "WHERE " & strStatus & _
                             strWhere & lblhidSortType.Text

        End If
        Dim PropertyDT As New Data.DataTable
        objDB.FillData(PropertyDT, "Property", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()

        'Creating a Paged Datasouce
        Dim objPaged As New PagedDataSource
        Dim FilterString As String = String.Empty
        Dim FilteredProperty As New Data.DataView(PropertyDT)

        'FilteredProperty.Sort = lblhidSortType.Text
        objPaged.DataSource = FilteredProperty
        objPaged.AllowPaging = True
        objPaged.PageSize = PageSize
        objPaged.CurrentPageIndex = CurrentPage

        lblHeadNoOfItem.Text = PropertyDT.Rows.Count
        lblFootNoOfItem.Text = PropertyDT.Rows.Count

        repProperty.DataSource = objPaged
        repProperty.DataBind()

        lblMaxPageCount.Text = objPaged.PageCount - 1
        lblTotalPage.Text = " of " & objPaged.PageCount

    End Sub

    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click

        SearchCompleteList()

    End Sub

    Protected Sub repProperty_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles repProperty.ItemCommand
        'Edited by minginn - To allow user to go back to the search page with same search selection
        'Back Page
        'Project
        'Road Name
        'Unit Number
        'Property Type
        'Location Name
        'List Type
        'Page Size
        'Current Page
        Dim strBack As String
        strBack = "transHistory.aspx" & "ڡ" & txtProject.Text.Trim & "ڡ" & txtRoadName.Text.Trim & "ڡ" & _
                txtUnitNumber.Text.Trim & "ڡ" & txtPropertyType.Text.Trim & "ڡ" & txtLocationName.Text.Trim & "ڡ" & _
                ddlListType.SelectedValue & "ڡ" & PageSize & "ڡ" & CurrentPage
        Session.Add("Back", strBack)
        If e.CommandName = "ViewTrans" Then
            If lblCurrentTransType.Text = "S" Then
                'Sales
                Dim TransactionID As Guid = New Guid(e.CommandArgument.ToString)
                Session.Add("Tid", TransactionID.ToString)
                Response.Redirect("stransview.aspx", False)
            Else
                'Rent
                Dim TransactionID As Guid = New Guid(e.CommandArgument.ToString)
                Session.Add("Tid", TransactionID.ToString)
                Response.Redirect("rtransview.aspx", False)
            End If
        ElseIf e.CommandName = "Compare" Then
            If lblCurrentTransType.Text = "S" Then
                Response.Redirect("stranscompare.aspx?id=" & SymmetricEncryptToHex(e.CommandArgument, "augment"))
            Else
                Response.Redirect("rtranscompare.aspx?id=" & SymmetricEncryptToHex(e.CommandArgument, "augment"))
            End If
        End If
    End Sub

    Protected Sub repProperty_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles repProperty.ItemDataBound

        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            CType(e.Item.FindControl("lblRepProjectType"), LinkButton).Attributes.Add("onmouseover", "return overlib('" & CType(e.Item.FindControl("lblRepTypeDesc"), Label).Text & "',ABOVE);")

            If CType(e.Item.FindControl("lblRepProject"), LinkButton).Text <> "" Then
                If CType(e.Item.FindControl("lblRepProjectPIcture"), Label).Text <> "" Then
                    CType(e.Item.FindControl("lblRepProject"), LinkButton).Attributes.Add("onmouseover", "return overlib('" & CType(e.Item.FindControl("lblRepProjectDesc"), Label).Text & "<hr /><img alt=""picture"" width=""100px"" height=""100px"" src=""project/" & CType(e.Item.FindControl("lblRepProjectPIcture"), Label).Text & """/>',ABOVE);")
                Else
                    CType(e.Item.FindControl("lblRepProject"), LinkButton).Attributes.Add("onmouseover", "return overlib('" & CType(e.Item.FindControl("lblRepProjectDesc"), Label).Text & "',ABOVE);")
                End If

            End If
            Dim strAddress As String = CType(e.Item.FindControl("lblRepUnitNumber"), Label).Text & ", " & CType(e.Item.FindControl("lblRepRoad"), LinkButton).Text & ", " & CType(e.Item.FindControl("lblRepLocation"), LinkButton).Text & ", " & CType(e.Item.FindControl("lblRepState"), LinkButton).Text & ", " & CType(e.Item.FindControl("lblRepCountry"), LinkButton).Text

            If CType(e.Item.FindControl("lblRepProject"), LinkButton).Text <> "" Then
                strAddress = strAddress & vbCrLf & "(" & CType(e.Item.FindControl("lblRepProject"), LinkButton).Text & ")"
            End If

            Select Case CType(e.Item.FindControl("lblRepTransacStatus"), Label).Text
                Case "1"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Text = "PENDING SIGNING"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Visible = True
                Case "2"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Text = "PENDING COLLECTION"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Visible = True
                Case "3"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Text = "COMPLETED"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Visible = True
                Case "0"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Text = "NEW"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Visible = True
                Case "4"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Text = "RELIST"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Visible = True
                Case "5"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Text = "RENEW"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Visible = True
                Case "7"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Text = "DELETE"
                    CType(e.Item.FindControl("lblRepTransacStatus"), Label).Visible = True
            End Select

            If CType(e.Item.FindControl("lblHideAbort"), Label).Text <> "" Then
                CType(e.Item.FindControl("lblRepTransacStatus"), Label).Text = "COMPLETED(ABORT)"
            End If

            If Session.Item("StaffType").ToString = "2" Then
                CType(e.Item.FindControl("imgbutViewTrans"), ImageButton).Visible = False
                CType(e.Item.FindControl("imgbutCompare"), ImageButton).Visible = False
                CType(e.Item.FindControl("lblGross"), LinkButton).Visible = False
                'lnkGross.Visible = False
            Else
                If Not IsDBNull(DataBinder.Eval(e.Item.DataItem, "GrossAmount")) Then
                    grossamount = CDbl(DataBinder.Eval(e.Item.DataItem, "GrossAmount"))
                Else
                    grossamount = 0
                End If
                sum += CDbl(grossamount)
            End If

           
        ElseIf e.Item.ItemType = ListItemType.Footer Then
            If Session.Item("StaffType").ToString = "2" Then
                CType(e.Item.FindControl("lblItemCount"), Label).Visible = False
                CType(e.Item.FindControl("lbltotal"), Label).Visible = False
            Else
                CType(e.Item.FindControl("lblItemCount"), Label).Text = String.Format("{0:#,##0.00}", sum)
            End If

        End If
    End Sub

    

#Region " Order By Coding "

    Private Function SortType(ByVal strSortType As String) As String
        Dim strSort As String
        If Right(strSortType, 1) = "▼" Then
            strSort = "ASC"
        Else
            strSort = "DESC"
        End If
        Return strSort
    End Function

    Protected Sub lnkUnitNo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkUnitNo.Click
        If lnkUnitNo.Text = "Unit No▼" Then
            lnkUnitNo.Text = "Unit No▲"
        Else
            lnkUnitNo.Text = "Unit No▼"
        End If

        lblhidSortType.Text = "ORDER BY UnitNumber " & SortType(lnkUnitNo.Text) & ", Road " & SortType(lnkRoad.Text) & _
                        ", Location " & SortType(lnkLocation.Text) & ", State " & SortType(lnkState.Text) & _
                        ", Country " & SortType(lnkCountry.Text) & ", Project " & SortType(lnkProject.Text) & _
                        ", Type " & SortType(lnkType.Text) & ", GrossAmount " & SortType(lnkGross.Text)

        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkRoad_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkRoad.Click
        If lnkRoad.Text = "Road▼" Then
            lnkRoad.Text = "Road▲"
        Else
            lnkRoad.Text = "Road▼"
        End If

        lblhidSortType.Text = "ORDER BY Road " & SortType(lnkRoad.Text) & ", UnitNumber " & SortType(lnkUnitNo.Text) & _
                        ", Location " & SortType(lnkLocation.Text) & ", State " & SortType(lnkState.Text) & _
                        ", Country " & SortType(lnkCountry.Text) & ", Project " & SortType(lnkProject.Text) & _
                        ", Type " & SortType(lnkType.Text) & ", GrossAmount " & SortType(lnkGross.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkLocation_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkLocation.Click
        If lnkLocation.Text = "Location▼" Then
            lnkLocation.Text = "Location▲"
        Else
            lnkLocation.Text = "Location▼"
        End If

        lblhidSortType.Text = "ORDER BY Location " & SortType(lnkLocation.Text) & ", UnitNumber " & SortType(lnkUnitNo.Text) & _
                        ", Road " & SortType(lnkRoad.Text) & ", State " & SortType(lnkState.Text) & _
                        ", Country " & SortType(lnkCountry.Text) & ", Project " & SortType(lnkProject.Text) & _
                        ", Type " & SortType(lnkType.Text) & ", GrossAmount " & SortType(lnkGross.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkState_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkState.Click
        If lnkState.Text = "State▼" Then
            lnkState.Text = "State▲"
        Else
            lnkState.Text = "State▼"
        End If

        lblhidSortType.Text = "ORDER BY State " & SortType(lnkState.Text) & ", UnitNumber " & SortType(lnkUnitNo.Text) & _
                        ", Road " & SortType(lnkRoad.Text) & ", Location " & SortType(lnkLocation.Text) & _
                        ", Country " & SortType(lnkCountry.Text) & ", Project " & SortType(lnkProject.Text) & _
                        ", Type " & SortType(lnkType.Text) & ", GrossAmount " & SortType(lnkGross.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkCountry_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkCountry.Click
        If lnkCountry.Text = "Country▼" Then
            lnkCountry.Text = "Country▲"
        Else
            lnkCountry.Text = "Country▼"
        End If

        lblhidSortType.Text = "ORDER BY Country " & SortType(lnkCountry.Text) & ", UnitNumber " & SortType(lnkUnitNo.Text) & _
                        ", Road " & SortType(lnkRoad.Text) & ", Location " & SortType(lnkLocation.Text) & _
                        ", State " & SortType(lnkState.Text) & ", Project " & SortType(lnkProject.Text) & _
                        ", Type " & SortType(lnkType.Text) & ", GrossAmount " & SortType(lnkGross.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkProject_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkProject.Click
        If lnkProject.Text = "Project▼" Then
            lnkProject.Text = "Project▲"
        Else
            lnkProject.Text = "Project▼"
        End If

        lblhidSortType.Text = "ORDER BY Project " & SortType(lnkProject.Text) & ", UnitNumber " & SortType(lnkUnitNo.Text) & _
                        ", Road " & SortType(lnkRoad.Text) & ", Location " & SortType(lnkLocation.Text) & _
                        ", State " & SortType(lnkState.Text) & ", Country " & SortType(lnkCountry.Text) & _
                        ", Type " & SortType(lnkType.Text) & ", GrossAmount " & SortType(lnkGross.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkType_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkType.Click
        If lnkType.Text = "Project Type▼" Then
            lnkType.Text = "Project Type▲"
        Else
            lnkType.Text = "Project Type▼"
        End If

        lblhidSortType.Text = "ORDER BY Type " & SortType(lnkType.Text) & ", UnitNumber " & SortType(lnkUnitNo.Text) & _
                        ", Road " & SortType(lnkRoad.Text) & ", Location " & SortType(lnkLocation.Text) & _
                        ", State " & SortType(lnkState.Text) & ", Country " & SortType(lnkCountry.Text) & _
                        ", Project " & SortType(lnkProject.Text) & ", GrossAmount " & SortType(lnkGross.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkGross_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkGross.Click
        If lnkGross.Text = "Gross Amount▼" Then
            lnkGross.Text = "Gross Amount▲"
        Else
            lnkGross.Text = "Gross Amount▼"
        End If

        lblhidSortType.Text = "ORDER BY GrossAmount " & SortType(lnkGross.Text) & ", UnitNumber " & SortType(lnkUnitNo.Text) & _
                        ", Road " & SortType(lnkRoad.Text) & ", Location " & SortType(lnkLocation.Text) & _
                        ", State " & SortType(lnkState.Text) & ", Country " & SortType(lnkCountry.Text) & _
                        ", Project " & SortType(lnkProject.Text) & _
                        ", Type " & SortType(lnkType.Text)
        btnSearch_Click(sender, e)
    End Sub

#End Region

    
End Class
